// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()

// 云函数入口函数
// 通过商品id获取商品详情
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let goodsId = Number(event.goodsId);
  let data = null;
  const result = await db.collection("goods").where({
    goodsId:goodsId
  }).get();
  if(result.data.length){
    data = result.data[0];
  }

  return {
    event,
    data
    // result
    // openid: wxContext.OPENID,
    // appid: wxContext.APPID,
    // unionid: wxContext.UNIONID,
  }
}